package com.magicstone.common.pagination.domain;

public class Page {
	
	//Input
    private int totalResult;    //总记录数  
    private int currentPage;    //当前页  
    private int showCount = 10; //每页显示记录数  
    
    //Output
    private int totalPage;      //总页数  
    private int currentResult;  //当前记录起始索引  

    public Page(){
    	
    }
    
    public Page(int page, int rows, int total){
    	totalResult = total;
    	currentPage = page;
    	showCount = rows;
    }
    
    public int getTotalPage() {  
        if(totalResult % showCount==0)  
            totalPage = totalResult/showCount;  
        else  
            totalPage = totalResult/showCount+1;  
        return totalPage;  
    } 
    
    public void setTotalPage(int totalPage) {  
        this.totalPage = totalPage;  
    }
    
    public int getTotalResult() {  
        return totalResult;  
    }
    
    public void setTotalResult(int totalResult) {  
        this.totalResult = totalResult;  
    }
    
    public int getCurrentPage() {  
        if(currentPage<=0)  
            currentPage = 1;  
        if(currentPage>getTotalPage())  
            currentPage = getTotalPage();  
        return currentPage;  
    }
    
    public void setCurrentPage(int currentPage) {  
        this.currentPage = currentPage;  
    }
    
    public int getShowCount() {  
        return showCount;  
    }  
    public void setShowCount(int showCount) {  
        this.showCount = showCount;  
    }  
    public int getCurrentResult() {  
        currentResult = (getCurrentPage() - 1) * getShowCount();  
        if(currentResult<0) {
            currentResult = 0;
        }
        return currentResult;  
    }  
    public void setCurrentResult(int currentResult) {  
        this.currentResult = currentResult;  
    }  
}